package com.ruoyi.publish.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.publish.domain.BestJenkinsBuilds;
import com.ruoyi.publish.domain.BestServiceTable;
import com.ruoyi.publish.manager.JenkinsJarDownloader;
import com.ruoyi.publish.mapper.BestJenkinsBuildsMapper;
import com.ruoyi.publish.mapper.BestServiceTableMapper;
import com.ruoyi.publish.service.IForTaskSysService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;

@Service
public class ForTaskSysServiceImpl implements IForTaskSysService {

    @Resource
    private JenkinsJarDownloader jarDownloader;

    @Resource
    private BestServiceTableMapper serviceTableMapper;

    @Resource
    private BestJenkinsBuildsMapper jenkinsBuildsMapper;

    @Override
    public void updateTaskStatus(String jobName) {
        BestServiceTable bestServiceTable = new BestServiceTable();
        bestServiceTable.setJobName(jobName);
        bestServiceTable = serviceTableMapper.selectBestServiceTableList(bestServiceTable).get(0);
        jarDownloader.downloadJAR(jobName, bestServiceTable.getRelativePath(), bestServiceTable.getServiceName()).thenAccept(res -> {
            jenkinsBuildsMapper.insertBestJenkinsBuilds(res);
        });
        System.out.println("请等待下载结果");

    }
}
